const getUseableIp = ip => {
  const res = [0, 0, 0, 0, 0, 0, 0]
  const [ipcode, netcode] = ip.split('~')
  const ipArr = ipcode.split('.')
  const netArr = netcode.split('.').map(item => parseInt(item))
  const ipnumArr = ipArr.map(item => parseInt(item))
  for (const item of ipnumArr) {
    if (item < 0 || item > 255) {
      res[5] += 1
      return res.join(' ')
    }
  }
  let ifZero = false
  let i = 0
  let err = false
  while (i < netArr.length) {
    if (!ifZero) {
      if (netArr[i] !== 255) {
        if (netArr[i] > 255 || netArr[i] < 0) {
          res[5] += 1
          return res.join(' ')
        }
        if (netArr[i] === 0) {
          ifZero = true
        } else {
          let index = 7
          let total = 0
          while (index) {
            total += 2 ** index
            if (total === netArr) {
              ifZero = true
              break
            } else {
              res[5] += 1
              return res.join(' ')
            }
          }
          if (err) {
            return res.join(' ')
          }
        }
      }
    } else {
      if (netArr !== 0) {
        res[5] += 1
        return res.join(' ')
      }
    }
    i++
  }
  const fnum = ipnumArr[0]
  // 过滤特殊ip
  if (ipnumArr.length !== 4) res[5] += 1
  if (fnum < 1 || fnum === 0 || fnum === 127 || !fnum) res[5] += 1
  if (ipnumArr[0] === 10) res[6] += 1
  if (ipArr[0] === 172 && ipArr[1] >= 16 && ipArr[1] <= 32) res[6] += 1
  if (ipArr[0] === 192 && ipArr[1] === 168) res[6] += 1
  if (fnum >= 1 && fnum <= 126) res[0] += 1
  if (fnum >= 128 && fnum <= 191) res[1] += 1
  if (fnum >= 192 && fnum <= 223) res[2] += 1
  if (fnum >= 224 && fnum <= 239) res[3] += 1
  if (fnum >= 240 && fnum <= 255) res[4] += 1

  console.log(res.join(' '))
}
console.log(getUseableIp('8.70.44.68~255.255.255.0'))
